package com.atguigu.gmall.product.controller;

import ch.qos.logback.core.joran.action.IADataForComplexProperty;
import com.atguigu.gmall.common.result.Result;

import com.atguigu.gmall.model.product.BaseTrademark;
import com.atguigu.gmall.product.service.BaseTrademarkService;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/admin/product/baseTrademark")
public class BaseTrademarkController {

    @Autowired
    ///admin/product/baseTrademark/{page}/{limit}
    private BaseTrademarkService baseTrademarkService;


    @GetMapping("/{page}/{limit}")
    public Result getbaseTrademark(@PathVariable Long page,
                                   @PathVariable Long limit) {
        //mybatis分页需要有类
        Page<BaseTrademark> baseTrademarkPage = new Page<>(page, limit);
        IPage iPage = baseTrademarkService.getbaseTrademark(baseTrademarkPage);
        return Result.ok(iPage);
    }

    @PostMapping("/save")
    ///admin/product/baseTrademark/save
    //@RequestBody 底层是通过jackson 将json转换为java对象
    public Result save(@RequestBody BaseTrademark baseTrademark) {
        //调用service方法
        baseTrademarkService.save(baseTrademark);
        return Result.ok();
    }


    @DeleteMapping("/remove/{id}")///admin/product/baseTrademark/remove/{id}
    public Result removeById(@PathVariable Long id) {
// 调用服务层方法
        baseTrademarkService.removeById(id);
        return Result.ok();
    }

    //回显数据 ///admin/product/baseTrademark/get/{id}
    @GetMapping("/get/{id}")
    public Result getById(@PathVariable Long id) {
        //调用服务层方法
        BaseTrademark baseTrademark = baseTrademarkService.getById(id);
        return Result.ok(baseTrademark);
    }

    //修改/admin/product/baseTrademark/update
    @PutMapping("/update")
    public Result update(@RequestBody BaseTrademark baseTrademark) {
        //调用服务层方法
        //修改数据
        baseTrademarkService.updateById( baseTrademark);
        return Result.ok();
    }

}
